package org.example.gof.proxy.dynamic;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * org.example.gof.proxy.dynamic
 *
 * @author 莫磊
 * @description
 * @date 2025/7/28
 */
public class CGLibTimeMethodInterceptor implements MethodInterceptor {
	@Override
	public Object intercept (Object target, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

		Long beginTime = System.currentTimeMillis();
		Object result = methodProxy.invokeSuper(target, objects);
		Long enTime = System.currentTimeMillis();
		System.out.println("CGLIB动态代理，执行时间：" + (enTime - beginTime));

		return result;
	}
}
